import requests,json
from autoTest_prtcApi.utils.log_util import logger

req = requests.session()


class RestClient:
    def __init__(self):
        self.prtc_url = 'http://192.168.1.9:8899'

    def excute_request(self, method, url, headers, **kwargs):
        logger.info(f"请求方法是:\n{method}")
        logger.info(f"请求的url是:\n{self.prtc_url + url}")
        logger.info(f"请求头是:\n{json.dumps(headers,indent=2,ensure_ascii=False)}")
        logger.info(f"请求参数是:\n{json.dumps(kwargs,indent=2,ensure_ascii=False)}")
        # 请求接口
        try:
            res = req.request(method=method, url=self.prtc_url + url, headers=headers, **kwargs)
        except Exception as e:
            logger.error(f"断言失败，失败原因是：\n{e}")
            raise
        return res
